package com.lv.pc.viewpagerphotocarousel;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by pc on 2014/12/14.
 */
public class MyViewPagerAdapter extends PagerAdapter {
    public List<View> pagerList;
    public MyViewPagerAdapter(List<View> pageList) {
        this.pagerList = pageList;
    }

    @Override
    public int getCount() {
        return pagerList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view ==object;
    }

    /**
     * 实例化当前item
     * @param container
     * @param position
     * @return
     */
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ((ViewPager)container).addView(pagerList.get(position),0);
        return pagerList.get(position);
    }

    /**
     * 销毁item
     * @param container
     * @param position
     * @param object
     */
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager)container).removeView(pagerList.get(position));
    }

}
